import Cookies from 'js-cookie'

const TokenKey = 'vue_admin_template_token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// 用户信息管理
export function setUserInfo(userInfo) {
  localStorage.setItem('name', userInfo.name || '')
  localStorage.setItem('avatar', userInfo.avatar || '')
  localStorage.setItem('role', userInfo.role || '')
}

export function getUserInfo() {
  return {
    name: localStorage.getItem('name') || '',
    avatar: localStorage.getItem('avatar') || '',
    role: localStorage.getItem('role') || ''
  }
}

export function removeUserInfo() {
  localStorage.removeItem('name')
  localStorage.removeItem('avatar')
  localStorage.removeItem('role')
}
